package com.foxmail.aroundme.boring.module.splash.module;

import com.foxmail.aroundme.boring.module.splash.presenter.ISplashPre;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;

/**
 * Created by gzl on 1/15/17.
 */

public class SplashInterImpl implements ISplashInter{

    private int stayTime = 500;

    private ISplashPre iSplashPre;

    public SplashInterImpl(ISplashPre iSplashPre) {
        this.iSplashPre = iSplashPre;
    }

    @Override
    public Subscription initSplash() {
        return Observable.create(new Observable.OnSubscribe<Object>() {
            @Override
            public void call(Subscriber<? super Object> subscriber) {
                subscriber.onNext(null);
                subscriber.onCompleted();
            }
        }).delaySubscription(stayTime, TimeUnit.MILLISECONDS).subscribe(new Subscriber<Object>() {
            @Override
            public void onNext(Object o) {
                if (iSplashPre != null) {
                    iSplashPre.jumpSplash();
                }
            }

            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }
        });
    }
}
